package cn.heima.com;

import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Iterator;

public class CollecttionDemo {
    public static void main(String[] args) {
        Collection<String>  list = new ArrayDeque<>();
        list.add("aaa");
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        list.add("ddd");
        // method1(list);
        //method2(list);
        //method3(list);
        method4(list);
}

    private static void method4(Collection<String> list) {
        Iterator<String> it = list.iterator();
        while(it.hasNext()){
        String s = it.next();
        if("aaa".equals(s)){
            it.remove();
        }
    }
        System.out.println(list);
    }

    //arrayList迭代器
    private static void method3(Collection<String> list) {
        Iterator<String> it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
    }

    private static void method2(Collection<String> list) {
        boolean lea =   list.contains("aaa");
        System.out.println(lea);
    }

    private static void method1(Collection<String> list) {
        list.removeIf((String s )->{
         if(s.equals("aaa")){
             return true;
         }else{
             return false;
         }
        });
        System.out.println(list);
    }
}
